import java.util.ArrayList;

import javax.swing.ImageIcon;


public class Pawn extends Piece
{
	boolean hasMoved;
	public Pawn()
	{
		super();
		hasMoved = false;
	}
	public Pawn(int x, int y, boolean isWhite)
	{
		super(x, y, isWhite);
		updateImage();
		hasMoved = false;
	}
	
	public void updateImage()
	{
		if(isBackgroundWhite())
		{
			if(isWhite() == true)
			{
				setImage(new ImageIcon("images/whitePawnWhite.gif", ""));
			}
			else
			{
				setImage(new ImageIcon("images/blackPawnWhite.gif", ""));
			}
		}
		else
		{
			if(isWhite() == true)
			{
				setImage(new ImageIcon("images/whitePawnBlack.gif", ""));
			}
			else
			{
				setImage(new ImageIcon("images/blackPawnBlack.gif", ""));
			}
		}
		if(isHighlightedRed())
		{
			highlightRed();
		}
	}
	
	public void highlightRed()
	{
		if(isWhite())
		{
//			System.out.println("I am the white Tiger");
			setImage(new ImageIcon("images/whitePawnRed.gif", ""));
			setIsHighlightedRed(true);
		}
		else
		{
//			System.out.println("I am the black Tiger");
			setImage(new ImageIcon("images/blackPawnRed.gif", ""));
			setIsHighlightedRed(true);
		}
	}
	public void deHighlight()
	{
		updateImage();
		setIsHighlightedRed(false);
	}
	
	public void setMoved()
	{
		hasMoved = true;
	}
	
	public ArrayList<Location> getPossibleMoves(Spot[][] spot)
	{
		ArrayList<Location> list = new ArrayList<Location>();
		
		if(isWhite())
		{
			if(getX()-1 >= 0 && (spot[getX()-1][getY()].getPiece() instanceof Empty))
			{
				list.add(new Location(getX()-1, getY()));
			}
			if(!hasMoved)
			{
				if(getX()-2 >= 0 && (spot[getX()-2][getY()].getPiece() instanceof Empty) && (spot[getX()-1][getY()].getPiece() instanceof Empty))
				{
					list.add(new Location(getX()-2, getY()));
	//				hasMoved = true;		//NEEDS TO BE FIXED.  This method only returns POSSIBLE moves, it doesn't necessarily mean a move will be made.
				}
			}
			if(getY()-1 >= 0)
			{
				if(!(spot[getX()-1][getY()-1].getPiece() instanceof Empty))
				{
					list.add(new Location(getX()-1, getY()-1));
				}
			}
			if(getY()+1 < 8)
			{
				if(!(spot[getX()-1][getY()+1].getPiece() instanceof Empty))
				{
					list.add(new Location(getX()-1, getY()+1));
				}
			}
		}
		else
		{
			if(getX()+1 < 8 && (spot[getX()+1][getY()].getPiece() instanceof Empty))
			{
				list.add(new Location(getX()+1, getY()));
			}
			if(!hasMoved)
			{
				if(getX()+2 < 8 && (spot[getX()+2][getY()].getPiece() instanceof Empty) && (spot[getX()+1][getY()].getPiece() instanceof Empty))
				{
					list.add(new Location(getX()+2, getY()));
	//				hasMoved = true;		//NEEDS TO BE FIXED.  This method only returns POSSIBLE moves, it doesn't necessarily mean a move will be made.
				}
				
			}
			if(getY()-1 >= 0)
			{
				if(!(spot[getX()+1][getY()-1].getPiece() instanceof Empty))
				{
					list.add(new Location(getX()+1, getY()-1));
				}
			}
			if(getY()+1 < 8)
			{
				if(!(spot[getX()+1][getY()+1].getPiece() instanceof Empty))
				{
					list.add(new Location(getX()+1, getY()+1));
				}
			}
		}

		
		removeOutOfBounds(list);
		removeSameColor(list, spot);
		
		return list;
		
	}

}
